﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

using ShootSearch.Core;
using ShootSearch.Util;
using ShootSearch.Spiders;
using ShootSearch.Util.Serializers;
using ShootSearch.Jobs;

using NUnit.Framework;
using System.Xml.Serialization;
using ShootSearch.FileSystem;

namespace ShootSearch.Tests.Core
{
    [TestFixture]
    public class AssemblyWithConfigTests
    {
        [Test]
        public void TestSingle()
        {
            AssemblyWithConfig expected = new AssemblyWithConfig();
            expected.Type = new AssemblyConfig(new HttpSpiderJob().GetType());
            //expected.ConfigType = new AssemblyConfig(new HttpSpiderJobConfig().GetType());
            expected.Config = new HttpSpiderJobConfig();
            

            string xml = XmlFormatter.ToXml(expected);
            Debug.WriteLine("Expected:");
            Debug.WriteLine(xml);

            AssemblyWithConfig actual = XmlFormatter.FromXml(xml, expected.GetType()) as AssemblyWithConfig;
            xml = XmlFormatter.ToXml(actual);
            Debug.WriteLine("Actual:");
            Debug.WriteLine(xml);

            HttpSpiderJobConfig ex = expected.Config as HttpSpiderJobConfig;
            HttpSpiderJobConfig ac = actual.Config as HttpSpiderJobConfig;
            Assert.AreEqual(ex.SaveConfig.BufferChunk, ac.SaveConfig.BufferChunk); //.SaveConfig.BufferChunk

        }

        [Test]
        public void ArrayTest()
        { 
        
        
        
        }


        [Test]
        public void SerializeTest()
        {
            TestClass expected = new TestClass();
            expected.List.Add(new AssemblyWithConfig(typeof(STFileSystem)));
            expected.List.Add(new AssemblyWithConfig(typeof(UrlParser)));

            string xml = XmlFormatter.ToXml(expected);
            Debug.WriteLine(xml);
            TestClass actual = XmlFormatter.FromXml(xml, expected.GetType()) as TestClass;

            Assert.AreNotEqual(null, actual);
            Assert.AreEqual(expected.List.Count, actual.List.Count);



        }

    }

    [Serializable]
    public class TestClass
    {
        //[XmlArray]
        [XmlElement("XX")]
        public AssemblyWithConfigArray List { get; set; }

        public TestClass()
        {
            List = new AssemblyWithConfigArray();
        }
    }
}
